package day06;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Scanner;

public class CalTotalAvg {
    public static void main(String[] args) {

        /*
           需求:<<主持人大赛>>有N为评委给选手打分
                选手的最终得分为:去掉最高分和最低分之后的N-2为评委的平均分
           要求:使用方法实现
         */

        double[] scores = inputData(6);//1)录入评委的评分
        double avg = calAvg(scores);
        System.out.println("平均分为:"+avg);


    }
/**  该方法用于录入N位评委的评分*/
    public static double[] inputData(int n){
        double[] scores = new double[n];
        Scanner scan = new Scanner(System.in);
        for (int i=0;i<scores.length;i++){
            System.out.println("请录入第"+(i+1)+"位评委的分数");
            scores[i]=scan.nextDouble();

        }
        Arrays.sort(scores);
        return scores;
    }

    /**  该方法用于计算平均分*/
//    public static double calAvg(double[] scores){
//        double[] a =new double[scores.length-2];
//        System.arraycopy(scores,1,a,0,scores.length-2);
//        double avg = 0.0;
//        for (int i=0;i<a.length;i++){
//            System.out.println(a[i]);
//            avg+=a[i];
//        }
//
//        avg/=(scores.length-2);
//        return avg;
//    }

    public static double calAvg(double[] scores) {
        double total = 0.0;
        double max = scores[0];
        double min = scores[0];
        for (int i = 0; i < scores.length; i++) {
            total += scores[i];
            if (max < scores[i]) {
                max = scores[i];
            }
            if (min < scores[i]) {
                min = scores[i];
            }
        }
        double avg = (total-max-min)/(scores.length-2);
        return avg;

    }
}
